package com.xdtech.game.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xdtech.core.orm.hibernate.HibernateDao;
import com.xdtech.game.model.Rank;

/**
 * 
 * @author max.zheng
 * @create 2015-03-16 23:17:03
 * @since 1.0
 * @see
 */
@Repository
public class RankDao extends HibernateDao<Rank, Long>{

	/**
	 * 
	 * @author max.zheng
	 * @create 2015-5-13下午11:16:53
	 * @modified by
	 * @param gameCode
	 * @param id
	 * @return
	 */
	public int getRank(String gameCode, Long id) {
		// SELECT B.uname,B.score,(SELECT COUNT(1) + 1 FROM game_rank A WHERE A.score > B.score AND a.`GAME_CODE`='fkss') PM FROM game_rank B WHERE B.`GAME_CODE`='fkss' ORDER BY PM;
		String sql = "SELECT (SELECT COUNT(1) + 1 FROM game_rank A WHERE A.score > B.score AND a.GAME_CODE='"+gameCode+"') PM FROM game_rank B WHERE B.GAME_CODE='"+gameCode+"' and B.id="+id+" ORDER BY PM";
		List obj = (List) excuteSql(sql);
		String rankIndex = obj!=null?obj.get(0).toString():"0";
		return Integer.valueOf(rankIndex);
	}

}
